/**
 * 
 */
package br.edu.ufcg.embedded.util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;


/**
 * Classe respons�vel por recuperar as informa��es para exporta��o dos dados.
 * @author Daniel
 */
public class FileManager
{
	private FileWriter fileWriter;
	private BufferedWriter bufferedWriter;
	
	public FileManager()
	{
	}
		
	/**
	 * Abre o arquivo para leitura
	 * @param pathName fullpath do arquivo
	 */
	public void openOrCreateFile(String pathName) throws IOException
	{		
		try {
			fileWriter = new FileWriter(pathName, true);
			bufferedWriter = new BufferedWriter(fileWriter);
		} catch (IOException e) {
			throw e;
		}
	}
	
	public void write(String text)
	{
		try {
			bufferedWriter.write(text);
			bufferedWriter.newLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void close()
	{
		try {
			bufferedWriter.flush();
			bufferedWriter.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void delete(String fileName)
	{
		File file = new File(fileName);
		
		if (file.exists())
			file.delete();
		
		file = null;
	}
}
